<?php include('header.php');?>
<?php
$roomtype_id = $_GET['id'];

if($_GET['action']=='edit') {

	if($_POST["roomtype_name"]!="" && $_POST["roomtype_id"]!= ""){

		$Query = mysql_query("SELECT roomtype_name FROM roomtype WHERE roomtype_name = '".$_POST["roomtype_name"]."' AND roomtype_price = '".$_POST["roomtype_price"]."'");
		$Num = mysql_num_rows($Query);
		if($Num>='1'){
			$save = $_POST["roomtype_name"]." มีอยู่แล้วกรุณาใช้ชื่ออื่นค่ะ";
			$roomtype_name = $_POST['roomtype_name'];
			$roomtype_id = $_POST["roomtype_id"];
			$roomtype_price = $_POST["roomtype_price"];
		} else {
			$QueryAdd = mysql_query("UPDATE roomtype SET roomtype_name = '".$_POST["roomtype_name"]."', roomtype_price = '".$_POST["roomtype_price"]."' WHERE roomtype_id = '".$_POST['roomtype_id']."' ");
			if($QueryAdd){
				$save = "<script>window.location='roomtype_manage.php'</script>";
			}
		}
	}
}

	$Query = mysql_query("SELECT * FROM roomtype WHERE roomtype_id = '".$_GET["id"]."' ");
	$Row = mysql_fetch_array($Query);
?>
<body>
<form action="?action=edit" name="formedit" method="post" id="formedit">
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading">
      <h1>แก้ไขประเภทห้องพัก</h1>
      <div class="buttons"><a onclick="chk_form('formedit');" class="button"><span>บันทึก</span></a><a onclick="location = 'roomtype_manage.php';" class="button"><span>ยกเลิก</span></a></div></div>
  <div class="content">
    <table class="form">
       <tr>
        <td>ชื่อประเภทห้องพัก : </td>
        <td><input name="roomtype_name" type="text" id="roomtype_name" maxlength="100" value="<?php if($roomtype_name==""){ echo $Row['roomtype_name'];} else {echo $roomtype_name;} ?>" /><input type="hidden" name="roomtype_id" value="<?php echo $roomtype_id; ?>"/></td>
      </tr>
       <tr>
        <td>ราคา : </td>
        <td><input name="roomtype_price" type="text" id="roomtype_price" maxlength="100" value="<?php if($roomtype_price==""){ echo $Row['roomtype_price'];} else {echo $roomtype_price;} ?>" /></td>
      </tr>
    </table>
	<?php echo "<br><font color=\"red\"><center>$save</center></font>"; ?>
  </div>
</div>
</form>
<?php mysql_close(); ?>
</body>
</html>
